package com.qs.core.utils;

import java.sql.Connection;
import javax.sql.DataSource;

public class ConnectionManager {
	
	private DataSource datasource;
	/*
	private final String url;
	//private final String driver;
	private final String id;
	private final String pwd;
	
	@ConstructorProperties({"","","",""})
	public ConnectionManager(String url,String driver,String id,String pwd){
		this.url = url;
		//this.driver = driver;
		this.id = id;
		this.pwd = pwd;
		try {
			Class.forName(driver);
		} catch (ClassNotFoundException e) {
			System.out.println("Include DB Driver");
		}
	}
	*/
	public Connection getConnection()throws Exception{		
		//Connection dbConnection = (Connection) DriverManager.getConnection(url,id,pwd);
		Connection dbConnection = datasource.getConnection();
		if(dbConnection == null)
			throw new Exception("Unable to connect to Database");
		return dbConnection;
	}

	public void setDatasource(DataSource datasource) {
		this.datasource = datasource;
	}
}
